﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using AuctionSite.App_Code.Modelos;

namespace AuctionSite.App_Code.DAL
{
    public class CategoriaDAL
    {
    
        
        public void Incluir(Categoria c)
        {
            SqlConnection cn = new SqlConnection();
            try
            {
                
                cn.ConnectionString = Dados.StringDeConexao;
                //command
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = cn;

                cmd.CommandText = "INSERT INTO categorias (cat_nome,cat_descricao) VALUES (@cat_nome,@cat_descricao);select @@IDENTITY;";

                cmd.Parameters.AddWithValue("@cat_nome", c.Cat_nome);
                cmd.Parameters.AddWithValue("@cat_descricao", c.Cat_descricao);

                cn.Open();
                c.Cat_id = Convert.ToInt32(cmd.ExecuteScalar());

            }
            catch (SqlException ex)
            {
                throw new Exception("Servidor SQL Erro:" + ex.Number);
            }
            catch (Exception ex)
            {
                throw new Exception("Erro:" + ex.Message);
            }
        }

        //#region Construtor
        //public CategoriaDAL() { }
        //#endregion
    }
}